﻿using AVCUMPlatform.DAL;
using AVCUMPlatform.Entities;
using AVCUMPlatform.Entities.Enum;
using AVCUMPlatform.HelperLibrary;
using AVCUMPlatform.MqConnection;
using AVCUMPlatform.ReadMqConfig;
using Newtonsoft.Json;
using System;

namespace AVCUMPlatform
{
    /// <summary>
    /// 消息处理管理
    /// </summary>
    public class TaskMsgQueueManager
    {
        /// <summary>
        /// 启动任务
        /// </summary>
        /// <param name="configuration"></param>
        public static void Start(IConfiguration configuration)
        {
            MqConnectionHelper._mqConfig = ReadMqConfigHelper.ReadMqConfig(configuration);
            MqConnectionHelper.FactoryConnectionInit();
            MqConnectionHelper.SendFactoryConnection();

        }
        /// <summary>
        /// 线程
        /// </summary>
        public static void TimeingThread(MessagequeuesSend messagequeues)
        {
            MqConnectionHelper.PublishExchange(JsonConvert.SerializeObject(messagequeues), messagequeues.Msgtype);
            DapperHelper.ExecuteCommand($"update {SQLHelper.GetTableName<Messagequeues>()} set `status` = 1 where `id` = {messagequeues.Id}");
        }
    }
}
